//
//  TheDeliveryVC.m
//  Logistics
//
//  Created by enzhoukeji on 2018/8/6.
//  Copyright © 2018年 puyue.com. All rights reserved.
//

#import "TheDeliveryVC.h"
//#import "SendCargoTVCell.h"
#import "SupplyOfGoodsTVCell.h"
#import "CarlenghtView.h"
@interface TheDeliveryVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView * supplyGoodsTV;
@property (nonatomic,strong) UIView * headView;
@property (nonatomic,strong) UILabel *placeLabale;//起始地
@property (nonatomic,strong) UILabel *destinationaLbale;//目的地
@property (nonatomic,strong) NSArray *titleArray;
@property (nonatomic,strong) NSArray *nameArray;
@property (nonatomic,strong) CarlenghtView *carView;
@end
@implementation TheDeliveryVC
-(UITableView *)supplyGoodsTV {
    if (!_supplyGoodsTV) {
        _supplyGoodsTV = [[UITableView alloc]initWithFrame:CGRectMake(0, kMainTopHeight, kMainScreen_width, kMainScreen_height - kMainTopHeight) style:UITableViewStyleGrouped];
        _supplyGoodsTV.backgroundColor = WGColor;
        _supplyGoodsTV.delegate = self;
        _supplyGoodsTV.separatorColor = [UIColor redColor];
        _supplyGoodsTV.dataSource = self;
        _supplyGoodsTV.separatorStyle = UITableViewCellSeparatorStyleNone;

    }
    return _supplyGoodsTV;
}

-(NSArray *)nameArray {
    if (!_nameArray) {
        _nameArray = [NSArray arrayWithObjects:@"车长车型",@"",@"货物类型",@"装车时间",@"装车方式",nil];
    }
    return _nameArray;
}
-(NSArray *)titleArray {
    if (!_titleArray) {
        _titleArray = [NSArray arrayWithObjects:@"支付方式",@"运费",@"备注",nil];
    }
    return _titleArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navTitle = @"发布货源";
    self.view.backgroundColor = WGColor;

    [self.view addSubview:self.supplyGoodsTV];
    // Do any additional setup after loading the view.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 5;
    }else if (section == 1) {
        return 3;
    }else{
        return 1;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 1) {
            SupplyOfGoodsTVCellSecond *cell=[tableView dequeueReusableCellWithIdentifier:@"SupplyOfGoodsTVCellSecond"];
            if (!cell) {
                cell=[[SupplyOfGoodsTVCellSecond alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SupplyOfGoodsTVCellSecond"];
            }
            return cell;
            
        }else{
            SupplyOfGoodsTVCell *cell=[tableView dequeueReusableCellWithIdentifier:@"SupplyOfGoodsTVCell"];
            if (!cell) {
                cell=[[SupplyOfGoodsTVCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SupplyOfGoodsTVCell"];
                cell.titleLabel.text =self.nameArray[indexPath.row];
            }
            cell.contentLabel.tag = indexPath.row + 100;
            cell.contentLabel.userInteractionEnabled = YES;
            if (cell.contentLabel.tag == 100) {
                [cell.contentLabel  addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
                    self.carView = [[CarlenghtView alloc] init];
                    [self.carView show];
                    ZFLog(@"0");
                }];
            }else if (cell.contentLabel.tag == 102) {
                [cell.contentLabel  addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
                    
                    ZFLog(@"2");
                }];
            }else if (cell.contentLabel.tag == 103) {
                [cell.contentLabel  addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
                    
                    ZFLog(@"3");
                }];
            }else if (cell.contentLabel.tag == 104) {
                [cell.contentLabel  addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
                    
                    ZFLog(@"4");
                }];
            }
            return cell;
        }
    }else if (indexPath.section == 1){
        SupplyOfGoodsTVCellThree *cell=[tableView dequeueReusableCellWithIdentifier:@"SupplyOfGoodsTVCellThree"];
        if (!cell) {
            cell=[[SupplyOfGoodsTVCellThree alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SupplyOfGoodsTVCellThree"];
        }
        cell.titleLabel.text = self.titleArray[indexPath.row];
        if (indexPath.row == 1) {
            cell.yuanLabel.hidden = NO;
        }else{
            cell.yuanLabel.hidden = YES;
        }
        return cell;
    }else{
        SupplyOfGoodsTVCellFour *cell=[tableView dequeueReusableCellWithIdentifier:@"SupplyOfGoodsTVCellFour"];
        if (!cell) {
            cell=[[SupplyOfGoodsTVCellFour alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SupplyOfGoodsTVCellFour"];
        }
        return cell;
    }
    
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        self.headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kMainScreen_width,GTFixHeightFlaot(60))];
        self.headView.backgroundColor = [UIColor whiteColor];
        [self createUIView];
        return self.headView ;
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return GTFixHeightFlaot(60);
    }else{
        return GTFixHeightFlaot(5);
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0 ){
        if (indexPath.row == 1) {
            return GTFixHeightFlaot(60);
        }else{
            return GTFixHeightFlaot(35);
        }
    }else if(indexPath.section == 1){
        return GTFixHeightFlaot(35);
    }else{
        return GTFixHeightFlaot(35);
    }
}
-(void)viewDidLayoutSubviews {
    
    if ([self.supplyGoodsTV respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.supplyGoodsTV setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.supplyGoodsTV respondsToSelector:@selector(setLayoutMargins:)])  {
        [self.supplyGoodsTV setLayoutMargins:UIEdgeInsetsZero];
    }
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}
-(void)createUIView {
    self.placeLabale = [UILabel labelWithSize:[UIFont systemFontOfSize:13] withColor:[UIColor grayColor] withText:@"   起始地"];
    self.placeLabale.layer .borderColor = [UIColor grayColor].CGColor;
    self.placeLabale.layer .borderWidth = 1.0;
    //label 点击方法
    [self.placeLabale addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
    }];
    UIButton * swapBut = [UIButton buttonWithTitle:nil withImageName:@"jiantou" withBGColor:nil Withlayer:NO];
    self.destinationaLbale = [UILabel labelWithSize:[UIFont systemFontOfSize:13] withColor:[UIColor grayColor] withText:@"   目的地"];
    //label 点击方法
    [self.destinationaLbale addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        
    }];
    self.destinationaLbale.layer .borderColor = [UIColor grayColor].CGColor;
    self.destinationaLbale.layer .borderWidth = 1.0;
    
    UILabel * labelLIn = [UILabel new];
    labelLIn.backgroundColor = [UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1];
    
    [self.headView addSubview:self.placeLabale];
    [self.headView addSubview:swapBut];
    [self.headView addSubview:self.destinationaLbale];
    [self.headView addSubview:labelLIn];
    [self.placeLabale mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(GTFixWidthFlaot(40)));
        make.top.equalTo(@(GTFixHeightFlaot(20)));
        make.height.equalTo(@(GTFixHeightFlaot(20)));
        make.width.equalTo(@(GTFixWidthFlaot(80)));
    }];
    [swapBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.placeLabale.mas_right).offset(GTFixWidthFlaot(15));
        make.top.equalTo(@(GTFixHeightFlaot(20)));
        make.height.equalTo(@(GTFixHeightFlaot(20)));
        make.width.equalTo(@(GTFixWidthFlaot(40)));
    }];
    [self.destinationaLbale mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(swapBut.mas_right).offset(GTFixWidthFlaot(15));
        make.top.equalTo(@(GTFixHeightFlaot(20)));
        make.height.equalTo(@(GTFixHeightFlaot(20)));
        make.width.equalTo(@(GTFixWidthFlaot(80)));
    }];
    [labelLIn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(GTFixWidthFlaot(5));
        make.width.mas_equalTo(kMainScreen_width);
    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
